package controller;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

import data.Data;

@SuppressWarnings("serial")
public class ViewLogServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		
		DBCollection collection = Data.data("logclient");
		DBObject object = collection.findOne();
		request.setAttribute("object", object);
		
		
		DBCollection collection2 = Data.data("loglinkclient");
		DBCursor cursor = collection2.find().sort(new BasicDBObject("date",-1)).limit(20);
		request.setAttribute("cursor", cursor);
		
		DBCollection coll = Data.data("logworker");
		DBObject object2 = coll.findOne();
		request.setAttribute("object2", object2);
		
		DBCollection collection3 = Data.data("loglinkworker");
		DBCursor cursor1 = collection3.find().sort(new BasicDBObject("date",-1)).limit(20);
		request.setAttribute("cursor1", cursor1);
		
		try {
			request.getRequestDispatcher("/viewlog.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
